﻿using FileManager.Toolkit;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DemoUpload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string path = "";
        string errMess = "";
        HttpFileCollection hfc1 = Request.Files;
        for (int i = 0; i < hfc1.Count; i++)
        {
            HttpPostedFile hpf = hfc1[i];
            // Upload Images
            if (DalatCooking.Core.Web.HttpHandlers.ImageUploadBase.ImageUpload(hpf, ref errMess, ref path) == true) 
            {
                Label1.Text += "\n" + path;
            }
            
        }
    }
    protected void btnCrop_Click(object sender, EventArgs e)
    {

        string fileNameIn = Server.MapPath(txtPicture.Text);
        string path = txtPicture.Text;
        string fileNameOut = Server.MapPath(Path.GetDirectoryName(path) + "\\" + Guid.NewGuid() + Path.GetExtension(path));

        Imaging.CropImage(fileNameIn, fileNameOut, new Rectangle(Convert.ToInt32(x.Value), Convert.ToInt32(y.Value), Convert.ToInt32(w.Value), Convert.ToInt32(h.Value)));

        string fileNameOutput = Path.GetDirectoryName(path) + "\\" + Path.GetFileName(fileNameOut);

        txtPicture.Text = string.Format("{0}{1}", "", fileNameOutput.Replace(@"\", "/"));
        imgpreview.Src = string.Format("{0}{1}", "", fileNameOutput.Replace(@"\", "/"));
        File.Delete(fileNameIn);
        //img1.Src = "/Uploads/Images/" + Path.GetFileName(fileNameIn);
    }
}